package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ResultEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "CIDRetainMapper")
public interface CIDRetainMapper extends BaseMapper<ResultEntity> {
    @Select("<script>" +
            " SELECT * FROM CIDHotRetainAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDRetainAll(@Param("Date") String Date, @Param("Percent") String Percent, @Param("page") int page, @Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM CIDHotRetainAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent})t  "+
            "</script>")
    int CIDRetainAllCount (@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            " SELECT DISTINCT Area FROM CIDHotRetainArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} "+
            "ORDER BY Area " +
            "</script>")
    List<Map<String, Object>> CIDRetainArea(@Param("Date") String Date, @Param("Percent") String Percent);

    @Select("<script>" +
            " SELECT * FROM CIDHotRetainArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDRetainByArea(@Param("Date") String Date, @Param("Percent") String Percent, @Param("Area") String Area,@Param("page") int page, @Param("pageSize") int pageSize);



    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM CIDHotRetainArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area})t  "+
            "</script>")
    int CIDRetainByAreaCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM CIDHotRetainPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDRetainByPopName(@Param("Date") String Date, @Param("Percent") String Percent, @Param("PopName") String PopName,@Param("page") int page, @Param("pageSize") int pageSize);



    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM CIDHotRetainPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND PopName=#{PopName})t  "+
            "</script>")
    int CIDRetainByPopNameCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("PopName") String PopName);


    @Select("<script>" +
            " SELECT DISTINCT PopName FROM CIDHotRetainAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} "+
            "ORDER BY PopName " +
            "</script>")
    List<Map<String, Object>> CIDRetainAreaPopName(@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT * FROM CIDHotRetainAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDRetainByAreaPopName(@Param("Date") String Date, @Param("Percent") String Percent, @Param("Area") String Area
            ,@Param("PopName") String PopName,@Param("page") int page, @Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT * FROM CIDHotRetainAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND Percent=#{Percent} AND Area=#{Area} AND PopName=#{PopName} )t  "+
            "</script>")
    int CIDRetainByAreaPopNameCount (@Param("Date") String Date, @Param("Percent") String Percent,@Param("Area") String Area,@Param("PopName") String PopName);

}
